﻿using System;
using System.Collections.Generic;
using System.Linq;
using Airport;
using System.Runtime.Serialization;

namespace Airport
{
    [DataContract]
    [KnownType(typeof(Point))]
    public class Node : Airport.INode, IEquatable<Node>
    {
        /// <note>
        /// we may or may not want a point data structure. it can make drawing easier for alec
        /// </note>
        private Point _coordinate;
        private int _xPos, _yPos, _nodeID;
        private float _latitude, _longitude;
        private List<Node> _neighbors;

        public Node() 
        {
            _coordinate = new Point(-1, -1);
            _xPos = -1;
            _yPos = -1;
            _nodeID = -1;
            _neighbors = new List<Node>();
        }

        public Node(int id, int x, int y)
        {
            _coordinate = new Point(x, y);
            _xPos = x;
            _yPos = y;
            _nodeID = id;
            _neighbors = new List<Node>(); // Should this be 
            // Should we set the lat and long explicitly?
        }

        /// <summary>
        /// getters and setters
        /// </summary>
        /// 

        [DataMember]
        public int NodeId
        {
            get
            {
                return _nodeID;
            }

            set
            {
                if (_nodeID != value)
                {
                    _nodeID = value;
                }
            }
        }

        [DataMember]
        public int XPos
        {
            get
            {
                return _xPos;
            }

            set
            {
                if (_xPos != value)
                {
                    _xPos = value;
                }
            }
        }

        [DataMember]
        public int YPos
        {
            get
            {
                return _yPos;
            }

            set
            {
                if (_yPos != value)
                {
                    _yPos = value;
                }
            }
        }

        [DataMember]
        public float Latitude
        {
            get { return _latitude; }
            set
            {
                if (_latitude != value)
                {
                    _latitude = value;
                }
            }
        }

        [DataMember]
        public float Longitude
        {
            get { return _longitude; }
            set
            {
                if (_longitude != value)
                {
                    _longitude = value;
                }
            }
        }

        [DataMember]
        public Point Coordinate
        {
            get { return _coordinate; }
            set
            {
                if (_coordinate != value)
                {
                    _coordinate = value;
                }
            }
        }

        [DataMember]
        public List<Node> Neighbors
        {
            get
            {
                return _neighbors;
            }

            set
            {
                if (_neighbors != value)
                {
                    _neighbors = value;
                }
            }
        }

        public bool Equals(Node other)
        {
            if (other == null)
            {
                return false;
            }

            if (_xPos == other._xPos
                && _yPos == other._yPos)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}